package com.aqie.easy.doublePointer;

/**
 * 917 仅仅反转字母 todo
 */
public class ReverseOnlyLetters {

    /**
     * 双指针
     * @param S
     * @return
     */
    public static String reverseOnlyLetters(String S) {
        if (S == null || S.length() <= 1) {
            return S;
        }
        int l = 0;
        int r = S.length() - 1;
        char[] arr = S.toCharArray();
        while (l < r) {
            char lc = arr[l];
            if (!Character.isLetter(lc)) {
                l++;
                continue;
            }
            char rc = arr[r];
            if (!Character.isLetter(rc)) {
                r--;
                continue;
            }
            arr[l++] = rc;
            arr[r--] = lc;
        }
        return new String(arr);
    }

    public static void main(String[] args) {
        String s = "Test1ng-Leet=code-Q!";
        // s = "ab-c";
        System.out.println(s);
        System.out.println(reverseOnlyLetters(s));

        System.out.println(Character.isLetter('T'));
    }


}
